# -*- coding: utf-8 -*-

class KeyboardHandler:
    
    handlers = {}
    
    
    @staticmethod
    def register(key, handler):
        if key not in KeyboardHandler.handlers:
            KeyboardHandler.handlers[key] = []
        KeyboardHandler.handlers[key].append(handler)
        
    @staticmethod
    def handle(keys, client):
        for key in KeyboardHandler.handlers:
            if keys[key]:
                for handler in KeyboardHandler.handlers[key]:
                    handler.handle(client)
    
    @staticmethod             
    def handleUp(key, client):
        if key in KeyboardHandler.handlers:
            for handler in KeyboardHandler.handlers[key]:
                handler.handleUp(client)